import axios from '@/libs/api.request'
import qs from 'qs'

export const getTableData = (params) => {
  return axios.request({
    url: 'admins/role/page?t='+new Date().getTime(),
    params,
    method: 'get'
  })
}

export const add = (data) => {
  return axios.request({
    url: 'admins/role/add',
    data: qs.stringify(data),
    method: 'post'
  })
}

export const update = (data) => {
  return axios.request({
    url: 'admins/role/update',
    data: qs.stringify(data),
    method: 'post'
  })
}

export const del = (data) => {
  return axios.request({
    url: 'admins/role/delete',
    data: qs.stringify(data),
    method: 'post'
  })
}

export const assign_resource = (data) => {
  let url = 'admins/role/assign_resource'
  data.resourceIds.map((item, index) => {
    if (index === 0) {
      url = url + '?resourceIds=' + item
    } else {
      url = url + '&resourceIds=' + item
    }
  })
  return axios.request({
    url: url,
    data: qs.stringify({
      id: data.id
    }),
    method: 'post'
  })
}

export const resource_tree = (params) => {
  return axios.request({
    url: 'admins/role/resource_tree?t='+new Date().getTime(),
    params,
    method: 'get'
  })
}
//新的权限接口
export const resource_tree_auth = (params) => {
  return axios.request({
    url: 'admins/role/resource_tree_auth?t='+new Date().getTime(),
    params,
    method: 'get'
  })
}
